#include<iostream>
#include<string>
#include<map>
#include<vector>
/*
一定要像这样使用assert!!!
一定要像这样使用assert!!!
一定要像这样使用assert!!!
即，必须在gcc build时定义DEBUG宏assert才会生效！！！
*/
#ifndef DEBUG
#define NDEBUG
#endif

#include<assert.h>

#define MS 10

using namespace std;

void split(vector<string> &words, string s, const string& del = " "){
    int start = 0;
    int end = s.find(del);
    while (end != -1) {
        words.push_back(s.substr(start, end - start));
        start = end + del.size();
        end = s.find(del, start);
    }
    words.push_back(s.substr(start, end - start));

}

int main(){
    string line, format;
    int n;
    map<string, string> opt2pars;
    vector<string> words;

    cin >> format >> n;
    assert(n==4);
    getchar();
    for(int i=0;i<n;i++){
        //清空
        words.clear();
        opt2pars.clear();
        line.clear();
        
        getline(cin,line);
        split(words, line);

        for(int j=1;j<words.size();j++){
            auto& word = words[j];            
            //合法选项         
            if(word[0] == '-' && word.size() == 2){      
                 int p = format.find(word[1]);
                //非法选项
                 if(p == -1)
                    break;
                
                if(opt2pars.find(word) == opt2pars.end()){
                    opt2pars[word] = "";
                }

                if(format[p+1]==':' &&  j+1 < words.size()){
                    opt2pars[word] = words[++j];
                }
               
            }else{
                break;
            }

        }

        //按格式输出
        cout << "Case "<< i+1 << ":";
        
        for(auto opt2par:opt2pars){
            cout << " " << opt2par.first;
            if(opt2par.second != ""){
                cout << " " << opt2par.second;
            }            
        }
        cout << endl;

    }

    return 0;
}